package tt.dz.order.pojo;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import tt.dz.order.dao.BaseDAOUtil;

/**
 * @Title 有贝先付退款回调记录
 * @author zhoutian   
 * @date 2015-11-26
 */
public class YouBeiRefundReturnRecord {
	//交易结果代码
	private String retCode;
	//交易结果描述
	private String retMsg;
	//签名方式,固定取值为RSA
	private String signType;
	//签名,用于验证回调请求参数是否被篡改过
	private String sign;
	//商户编号，商户（电桩）在有贝先付支付平台上开设的商户号码，为18位数字
	private String partnerNo;
	//商户退款单号，商户系统唯一标识该退款的流水号
	private String outRefundNo;
	//退款金额
	private String refundFee;
	//有贝先付退款流水号
	private String tradeNo;
	//退款申请: 0   退款处理中：1   退款成功：2   退款失败：3
	private String tradeStatus;
	//清算日期
	private String settleDate;
	//创建时间
	private Date createTime;

	public String getRetCode() {
		return retCode;
	}

	public void setRetCode(String retCode) {
		this.retCode = retCode;
	}

	public String getRetMsg() {
		return retMsg;
	}

	public void setRetMsg(String retMsg) {
		this.retMsg = retMsg;
	}

	public String getSignType() {
		return signType;
	}

	public void setSignType(String signType) {
		this.signType = signType;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getPartnerNo() {
		return partnerNo;
	}

	public void setPartnerNo(String partnerNo) {
		this.partnerNo = partnerNo;
	}

	public String getOutRefundNo() {
		return outRefundNo;
	}

	public void setOutRefundNo(String outRefundNo) {
		this.outRefundNo = outRefundNo;
	}

	public String getRefundFee() {
		return refundFee;
	}

	public void setRefundFee(String refundFee) {
		this.refundFee = refundFee;
	}

	public String getTradeNo() {
		return tradeNo;
	}

	public void setTradeNo(String tradeNo) {
		this.tradeNo = tradeNo;
	}

	public String getTradeStatus() {
		return tradeStatus;
	}

	public void setTradeStatus(String tradeStatus) {
		this.tradeStatus = tradeStatus;
	}

	public String getSettleDate() {
		return settleDate;
	}

	public void setSettleDate(String settleDate) {
		this.settleDate = settleDate;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public YouBeiRefundReturnRecord() {
		this.createTime = new Date();
	}
	
	public YouBeiRefundReturnRecord(Map<String, String> params) {
		this.retCode = params.get("ret_code");
		this.retMsg = params.get("ret_msg");
		this.signType = params.get("sign_type");
		this.sign = params.get("sign");
		this.partnerNo = params.get("oid_partner");
		this.outRefundNo = params.get("no_refund");
		this.refundFee = params.get("money_refund");
		this.tradeNo = params.get("oid_refundno");
		this.tradeStatus = params.get("sta_refund");
		this.settleDate = params.get("settle_date");
		this.createTime = new Date();
	}
	
	public void save(){
		String sql = "insert into Order_YouBei_Refund_Return_Record(retCode, retMsg, signType, sign, partnerNo, outRefundNo, refundFee, tradeNo, tradeStatus， settleDate, createTime) values(:retCode, :retMsg, :signType, :sign, :partnerNo, :outRefundNo, :refundFee, :tradeNo, :tradeStatus， :settleDate, :createTime)";
		BaseDAOUtil.updateObject(sql, this);
	}
	
	public void update(){
		String sql = "update Order_YouBei_Refund_Return_Record set retCode = :retCode, retMsg = :retMsg, signType = :signType, sign = :sign, partnerNo = :partnerNo, outRefundNo = :outRefundNo, refundFee = :refundFee, tradeNo = :tradeNo, tradeStatus = :tradeStatus， settleDate = :settleDate, createTime = :createTime where orderNo = :orderNo";
		BaseDAOUtil.updateObject(sql, this);
	}
	
	public static YouBeiRefundReturnRecord getBy(String outRefundNo){
		String sql = "select retCode, retMsg, signType, sign, partnerNo, outRefundNo, refundFee, tradeNo, tradeStatus， settleDate, createTime from Order_YouBei_Refund_Return_Record where outRefundNo = :outRefundNo";
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("outRefundNo", outRefundNo);
		return BaseDAOUtil.queryForObject(sql, paramMap, YouBeiRefundReturnRecord.class);
	}
}
